package com.cn.unarmed.views;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cn.unarmed.activity.R;

/**
 * 不用系统的原生title，自定义布局以及点击事件
 */
public class BaseTitleLayout extends LinearLayout {

    public TextView title, tv_meshare, tv_mercv;
    public Button left, right;
    private View titleBar;

    public LinearLayout lay_text;

    public BaseTitleLayout (Context context,int layoutId){
        super(context);
        this.setOrientation(LinearLayout.VERTICAL);
        LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        titleBar = layoutInflater.inflate(R.layout.title_bar,this,false);
        addView(titleBar);

        View content = layoutInflater.inflate(layoutId,null);
        ViewGroup.LayoutParams contentParam = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
        addView(content,contentParam);

        title = getView(R.id.header_title);
        left = getView(R.id.header_left_btn);
        right = getView(R.id.header_right_btn);
        tv_meshare = getView(R.id.tv_meshare);
        tv_mercv = getView(R.id.tv_mercv);
        lay_text = getView(R.id.ll_heater);
        lay_text.setVisibility(GONE);
    }

    public View getTitleBar() {
        return titleBar;
    }

    private <T extends View> T getView(int id) {
        return (T) titleBar.findViewById(id);
    }
}
